<?php
namespace app\admin\model;
use think\Model;
use think\Db;
class OrderModer extends Model{
    public function index(){
        $order_list = Db::name('order')->order('or_id desc')->paginate(10);
        return $order_list;
    }
    public function indexshop(){
        return Db::name('store')->order('ma_id desc')->paginate(10);
    }
    public function indexshopid($ma_id){
        return Db::name('order')->where('ma_id',$ma_id)->paginate(10);
    }
    public function order_add($or_status,$ma_id){
        if ($ma_id != ''){
            $where['ma_id'] = $ma_id;
            $where['or_status'] = $or_status;
        }else {
            $where['or_status'] = $or_status;
        }
        $order_list = Db::name('order')->where($where)->order('or_id desc')->paginate(10);
        return $order_list;
    }
    public function order_details($or_ordersn){
        $order_list = Db::name('order')->where('or_ordersn',$or_ordersn)->order('or_id desc')->find();
        return $order_list;
    }
    public function order_search($or_ordersn){
        $order_list = Db::name('order')->where('or_ordersn',$or_ordersn)->paginate(10);
        return $order_list;
    }
    public function month($or){
        switch (true) {
            case $or === '1':
                $add = Db::name('order')
                    ->whereTime('or_paytime', 'm')
                    ->paginate(10);
                return $add;
                break;
            case $or === '2':
                $num = (ceil(date("n") / 3) * 3 - 3) + 1;
                $d['staTime'] = date('Y-m-01', strtotime('-' . (date("n") - $num + 3) . " month"));
                $d['endTime'] = date('Y-m-01', strtotime('+' . ($num - date("n")) . " month"));
                $add = Db::name('order')
                    ->whereBetweenTime('or_paytime', $d['staTime'], $d['endTime'])
                    ->paginate(10);
                return $add;
                break;
            case $or === 3:
                $add = Db::name('order')
                    ->whereTime('or_paytime', 'y')
                    ->paginate(10);
                return $add;
                break;
            default:
        }
    }
}
